﻿using System;
using QuanLyHopDong.Biz;
using QuanLyHopDong.Biz.Model;
using QuanLyHopDong.Web.Common;
using Resources;

namespace QuanLyHopDong.Web.HopDong
{
    public partial class HopDongChiTiet : System.Web.UI.Page
    {
        #region Properties

        private static HopDongBiz _hopDongBiz;
        private static HopDongBiz HopDongManager
        {
            get { return _hopDongBiz ?? (_hopDongBiz = new HopDongBiz()); }
        }

        private int _hopDongId;
        private int HopDongId
        {
            get
            {
                if (_hopDongId <= 0)
                    int.TryParse(Request.QueryString["hopDongId"], out _hopDongId);
                return _hopDongId;
            }
        }

        private HopDongView _hopDongView;
        private HopDongView CurrentHopDongView
        {
            get
            {
                if (_hopDongView == null && HopDongId > 0)
                {
                    _hopDongView = HopDongManager.GetById(HopDongId);
                }
                return _hopDongView;
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadHopDongData();
            }
        }

        private void LoadHopDongData()
        {
            ltrTenDonVi.Text = CurrentHopDongView.TenDonVi;
            ltrSoHopDong.Text = CurrentHopDongView.SoHopDong;
            ltrTenHopDong.Text = CurrentHopDongView.TenHopDong;
            ltrLoaiDuAn.Text = CurrentHopDongView.LoaiDuAn;
            ltrNgayKy.Text = CurrentHopDongView.NgayKy.HasValue
                ? CurrentHopDongView.NgayKy.Value.ToString(GlobalStrings.DateFormat)
                : string.Empty;
            ltrNgayBatDauThiCong.Text = CurrentHopDongView.NgayBatDauThiCong.HasValue
                ? CurrentHopDongView.NgayBatDauThiCong.Value.ToString(GlobalStrings.DateFormat)
                : string.Empty;
            ltrNgayKetThucThiCong.Text = CurrentHopDongView.NgayKetThucThiCong.HasValue
                ? CurrentHopDongView.NgayKetThucThiCong.Value.ToString(GlobalStrings.DateFormat)
                : string.Empty;
            ltrNgayHoanThien.Text = CurrentHopDongView.NgayHoanThien.HasValue
                ? CurrentHopDongView.NgayHoanThien.Value.ToString(GlobalStrings.DateFormat)
                : string.Empty;
            ltrGiaTriHopDongChuaVAT.Text = string.Format("{0:N0}", CurrentHopDongView.GiaTriHopDongChuaVAT);
            ltrTongGiaTriHopDong.Text = string.Format("{0:N0}", CurrentHopDongView.TongGiaTriHopDong);
            ltrGiaTriVatTu.Text = string.Format("{0:N0}", CurrentHopDongView.GiaTriVatTu);
            ltrGiaTriNhanCong.Text = string.Format("{0:N0}", CurrentHopDongView.GiaTriNhanCong);
            ltrChiPhiKhac.Text = string.Format("{0:N0}", CurrentHopDongView.ChiPhiKhac);
            ltrVat.Text = string.Format("{0:N0}", CurrentHopDongView.VAT);
            ltrTrangThaiHopDong.Text = WebCommon.TrangThaiHopDongStrings[CurrentHopDongView.TrangThai];
        }
    }
}